package com.zallds.utils;

import com.zallds.model.Source;
import org.springframework.util.ResourceUtils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by liujian on 2019/12/15.
 */
public class ReadFileUtil {

    /**
     * 按行读取文件
     *
     * @param strFile
     */
    public static List<Source> readFileByLine(String strFile) {
        List<Source> list = new ArrayList<>();
        try {
            File file = new File(strFile);
            BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
            String strLine = null;
            while (null != (strLine = bufferedReader.readLine())) {
                Source source = new Source();
                String[] arr = strLine.split("\\|");
                source.setUrl(arr[0]);
                source.setDbName(arr[1]);
                source.setUserName(arr[2]);
                source.setPasswd("********");
                list.add(source);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }

    public static void main(String[] args) {
        ReadFileUtil.readFileByLine("/mysqlFile/source.txt");
    }
}
